
$(function () {
    var shareDetail = {
        init: function () {
            this.event();
        },
        event: function () {
            // 通用分享首页
            this.shareDetail();
        },
        // 通用分享首页
        shareDetail: function () {
            // 使用 jq 动态加载 微信配置
            var ajax = new AjaxHelper();
            ajax.post('/getsignature',{url:location.href.split('#')[0]}, function (data) {
                console.log(data);
                // 开始配置微信JS-SDK
                wx.config({
                    debug: false,
                    appId: data.appId,
                    timestamp: data.timestamp,
                    nonceStr: data.nonceStr,
                    signature: data.signature,
                    jsApiList: [
                        'checkJsApi',
                        'onMenuShareTimeline',
                        'onMenuShareAppMessage',
                        'onMenuShareQQ',
                        'onMenuShareWeibo',
                        'onMenuShareQZone',
                        'hideMenuItems',
                        'showMenuItems',
                    ]
                });
                // 调用微信API
                wx.ready(function() {
                    var sdata = {
                        title: $('#post-title').text(),
                        desc:  $('#post-content').text(),
                        link:  location.href,
                        imgUrl: $('.swiper-wrapper').find('.swiper-slide').eq(0).find('img').attr('src')
                        success: function() {
                            // alert('用户确认分享后执行的回调函数');
                        },
                        cancel: function() {
                            // alert('用户取消分享后执行的回调函数');
                        }
                    };
                    // 分享到朋友圈
                    wx.onMenuShareTimeline(sdata);
                    // 分享给朋友
                    wx.onMenuShareAppMessage(sdata);
                    // 分享到QQ
                    wx.onMenuShareQQ(sdata);
                    // 分享到腾讯微博
                    wx.onMenuShareWeibo(sdata);
                    // 分享到QQ空间
                    wx.onMenuShareQZone(sdata);
                    // 要显示的菜单项
                    // wx.showMenuItems({
                    //     menuList: [] 
                    // });
                    // 要隐藏的菜单项
                    wx.hideMenuItems({
                        menuList: [
                            "menuItem:favorite",
                            "menuItem:share:facebook",
                            "menuItem:editTag",
                            "menuItem:delete",
                            "menuItem:copyUrl",
                            "menuItem:originPage",
                            "menuItem:readMode",
                            "menuItem:openWithQQBrowser",
                            "menuItem:openWithSafari",
                            "menuItem:share:email",
                            "menuItem:share:brand"]
                    });
                });
            });
        }
    }
    shareDetail.init();    
})